package com.ev.apis.controller.asl;

import com.ev.framework.annotation.EvApiByToken;
import com.ev.framework.utils.R;
import com.ev.asl.config.JiateConstant;
import com.ev.asl.service.KisBillOfPullService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 金蝶KIS同步API   加特 同步KIS旗舰版
 */
@Slf4j
@Api(value = "/", tags = "拉取---同步KIS API-业务单据 ")
@RestController
public class KisBillOfPullSyncApiController {

    @Resource
    private KisBillOfPullService kisBillOfPullService;

    @EvApiByToken(value = "/apis/KisSync/billInfo/shipmentsNotice", method = RequestMethod.GET)
    @ApiOperation("发货通知--同一个用户操作间隔控制在60秒内")
    public R shipmentsNoticeSync() {
        try {
            return kisBillOfPullService.shipmentsNoticeSync(JiateConstant.SHIPMENTS_NOTIFICATION);
        } catch (Exception ex) {
            return R.error("发货通知 同步失败，请稍后重试或联系管理员，失败原因:"+ex.getMessage());
        }
    }


    /**
     * 生产计划默认拉取的是已下达的状态的单据！
     * @return
     */
    @EvApiByToken(value = "/apis/KisSync/billInfo/production", method = RequestMethod.GET)
    @ApiOperation("生产计划-生产投料单 --双同步接口--------同一个用户操作间隔控制在60秒内")
    public R productionSync() {
        productionSyncOfSync();
        log.info("------异步执行 投料");
        return kisBillOfPullService.productionFeedingSync(JiateConstant.PRODUCTION_FEEDING);
    }

    @Async("createPDFExecutor")
    public  void productionSyncOfSync(){
        kisBillOfPullService.productionSync(JiateConstant.PRODUCTION_PLAN);
    }


//    @EvApiByToken(value = "/apis/KisSync/billInfo/feeding", method = RequestMethod.GET)
//    @ApiOperation("生产投料单--同一个用户操作间隔控制在60秒内")
//    public R feedingSync() {
//        try {
//            return kisBillOfPullService.productionFeedingSync(JiateConstant.PRODUCTION_FEEDING);
//        } catch (Exception ex) {
//            return R.error("生产计划 同步失败，请稍后重试或联系管理员，失败原因:"+ex.getMessage());
//        }
//    }


    @EvApiByToken(value = "/apis/KisSync/billInfo/bom", method = RequestMethod.GET)
    @ApiOperation("BOM--同一个用户操作间隔控制在60秒内")
    public R bomSync() {
        try {
            return kisBillOfPullService.bomSync(JiateConstant.BOM_BILL);
        } catch (Exception ex) {
            return R.error("发货通知 同步失败，请稍后重试或联系管理员，失败原因:"+ex.getMessage());
        }
    }

}
